<template>
    <div class="container">
        <template v-if="!isPhone">
            <header>
                <img class="top-cover" src="../../public/images/tab-cover.png" alt="">
                <div class="tabs">
                    <div class="tab-item">
                        <span class="tab-title">{{tabList[0].name}}:</span>
                        <ul class="tab-main">
                            <li class="tab-name" :class="{'tab-active':select.service==item.id}"
                                v-for="item in tabList[0].list"
                                :key="item.id" @click="select.service = item.id">{{item.name}}
                            </li>
                        </ul>
                    </div>
                    <div class="tab-item">
                        <span class="tab-title">{{tabList[1].name}}:</span>
                        <ul class="tab-main">
                            <li class="tab-name" v-for="item in tabList[1].list" :key="item.id"
                                :class="{'tab-active':select.level==item.id}">{{item.name}}
                            </li>
                        </ul>
                    </div>
                </div>
            </header>
        </template>
        <!--移动端hedaer-->
        <template v-else>
            <header class="m-header">
                <ul class="tab-items">
                    <li class="tab-item" v-for="(item,index) in tabList" :key="index" @click="choice(item)">
                        <span>{{item.name}}</span>
                        <i class="el-icon-caret-bottom"></i>
                    </li>
                </ul>
            </header>
            <div class="tabs-select-box" v-if="popupVisible">
                <div class="tabs-mask" @click="popupVisible=false" @touchmove.prevent @mousewheel.prevent></div>
                <ul class="tabs-center">
                    <li class="item" v-for="(item,index) in selectInfo.list" :key="index"
                        :class="{'item-active':item.id==select[selectInfo.value].id}">
                        {{item.name}}
                    </li>
                </ul>
            </div>
        </template>
        <section>
            <div class="sort-content" v-if="!isPhone">
                <span class="sort-title">{{tabList[2].name}}:</span>
                <ul class="sort-main">
                    <li class="sort-name" v-for="item in tabList[2].list" :key="item.id"
                        :class="{'sort-active':select.sort==item.id}">{{item.name}}
                    </li>
                </ul>
            </div>

            <ul class="service-items"
                v-infinite-scroll="loadMore"
                infinite-scroll-disabled="loading"
                infinite-scroll-distance="5">
                <li class="service-item" v-for="item in 10">
                    <div class="s-cover"></div>
                    <div class="s-info">
                        <p class="s-title row2">深圳小成sad发生地方23我12312是的发送到发送到2</p>
                        <div class="s-bottom">
                            <span class="s-price">¥1600</span>
                            <span class="s-count">
                            <i class="user-icon"></i>
                            2200人已买
                        </span>
                        </div>
                    </div>
                </li>
            </ul>
        </section>
        <el-pagination
            :page-size="20"
            :pager-count="11"
            layout="prev,pager,slot,next"
            :total="1000"
            prev-text="上一页"
            next-text="下一页"
            v-if="!isPhone">
        </el-pagination>
    </div>
</template>

<script>
    import {mapState} from 'vuex'
    import Vue from 'vue'
    import {InfiniteScroll} from 'mint-ui';

    Vue.use(InfiniteScroll);
    export default {
        name: "RiseEdu",
        data() {
            return {
                tabList: [
                    {
                        name: '服务列别',
                        value: 'service',
                        list: [
                            {name: '全部', id: 1},
                            {name: '线下单项服务', id: 2},
                            {name: '线下全包服务', id: 3},
                        ]
                    }, {
                        name: '字段',
                        value: 'level',
                        list: [
                            {name: '全部', id: 1},
                            {name: '幼升小', id: 2},
                            {name: '小升初', id: 3},
                            {name: '高考', id: 4},
                        ]
                    }, {
                        name: '排列方式',
                        value: 'sort',
                        list: [
                            {name: '综合排序', id: 1},
                            {name: '热门服务', id: 2},
                            {name: '最新服务', id: 4},
                        ]
                    }
                ],
                selectInfo: {},
                select: {
                    service: 1,
                    level: 1,
                    sort: 1
                },
                popupVisible: false,
                loading: false
            }
        },
        computed: {
            ...mapState(['isPhone'])
        },
        mounted() {
            this.$store.commit(types.SET_TAB_STYLE, 'white')
        },
        methods: {
            choice(item) {
                console.log(item)
                this.selectInfo = item
                this.popupVisible = true
            },
            loadMore() {
                console.log(123)
                this.loading = true;
                setTimeout(() => {
                    this.loading = false;
                }, 2500);
            }
        }
    }
</script>

<style scoped lang="scss">
    .container {
        width: 1200px;
        margin: 97px auto 0;
    }

    .top-cover {
        width: 1200px;
        height: 110px;
    }

    .tabs {
        width: 100%;
        height: 112px;
        margin-top: 24px;
        background: #fff;
        box-shadow: 0px 3px 6px rgba(5, 23, 56, 0.11);
        border-radius: 10px;
        .tab-item {
            display: flex;
            align-items: center;
            padding-left: 20px;
            height: 50%;
            font-size: 14px;
            .tab-title {
                display: inline-flex;
                width: 70px;
                color: #07111B;
            }
            .tab-main {
                display: flex;
                margin-left: 15px;
            }
            .tab-name {
                padding: 2px 17px;
                color: #646464;
            }
            .tab-active {
                padding: 2px 11px;
                margin: 0 11px;
                background: #1E80FF;
                border-radius: 4px;
                color: #fff;
            }
        }
    }

    .sort-content {
        display: flex;
        align-items: center;
        height: 40px;
        margin-top: 32px;
        background: #E2E7F1;
        border-radius: 4px;
        padding-left: 20px;
        font-size: 14px;
        color: #07111B;
        .sort-title {
            width: 70px;
        }
        .sort-main {
            display: flex;
            align-items: center;
            height: 100%;
        }
        .sort-name {
            padding-left: 20px;
        }
        .sort-active {
            color: #1E80FF;
        }
    }

    .service-items {
        display: flex;
        flex-wrap: wrap;
        .service-item {
            display: flex;
            flex-direction: column;
            width: 25%;
            height: 254px;
            padding: 0 8px;
            margin-top: 30px;
            &:nth-child(4n) {
                padding-right: 0;
            }
            &:nth-child(4n+1) {
                padding-left: 0;
            }
            .s-cover {
                width: 100%;
                height: 157px;
                background: url("../../public/images/home-bg.png");
                background-size: cover;
                border-top-left-radius: 10px;
                border-top-right-radius: 10px;
            }
            .s-info {
                flex: 1;
                height: 100%;
                background: #fff;
                border-bottom-left-radius: 10px;
                border-bottom-right-radius: 10px;
                .s-title {
                    padding: 10px;
                    font-size: 14px;
                    font-weight: bold;
                }
                .s-bottom {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    padding: 8px 10px 0;
                    .s-price {
                        font-size: 14px;
                        color: #1E80FF;
                    }
                    .s-count {
                        display: flex;
                        align-items: center;
                        font-size: 12px;
                        color: #999;
                    }
                    .user-icon {
                        display: inline-flex;
                        width: 14px;
                        height: 14px;
                        margin-top: 1px;
                        background: url("../../public/images/user-ico.png");
                        background-size: 100% 100%;
                    }
                }
            }
        }
    }

    @media screen and (max-width: 750px) {
        .container {
            width: auto !important;
            margin: 0;
        }
        .m-header {
            position: relative;
            z-index: 2;
            .tab-items {
                display: flex;
                align-items: center;
                justify-content: space-around;
                padding: 0 .4rem;
                height: 1.173rem;
                background: #fff;
                font-size: .373rem;
            }
        }
        .tabs-mask {
            position: fixed;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            background: #000;
            opacity: .3;
            z-index: 1;
        }
        .tabs-center {
            position: absolute;
            width: 100%;
            padding: 20px;
            background: #fff;
            z-index: 2;
            .item {
                height: 1.173rem;
                line-height: 1.173rem;
                font-size: .373rem;
            }
        }
        .service-items {
            padding: 0 .2rem;
            .service-item {
                width: 50%;
                height: 4.9rem;
                padding: 0 .2rem !important;
                .s-title {
                    padding-bottom: 0 !important;
                    font-size: .37rem !important;
                }
                .s-price,
                .s-count {
                    font-size: .32rem !important;
                }
                .user-icon {
                    width: .37rem !important;
                    height: .37rem !important;
                }
            }
        }
    }
</style>
